package com.ruyuan.dfs.server;

import com.ruyuan.dfs.common.NettyPacketDecoder;
import com.ruyuan.dfs.common.NettyPacketEncoder;
import com.ruyuan.dfs.model.common.FileChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldPrepender;

/**
 * @description:
 * @Author gckj
 * @Email:
 * @Date: 2024/8/2 14:00
 * @Version 1.0
 */
public class BaseChannelInitializer extends ChannelInitializer<SocketChannel> {

    public Integer MAX_BYTES = 10 * 1024 * 1024;

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast(
                // InBound
                new NettyPacketDecoder(MAX_BYTES),
                new LengthFieldPrepender(3),
                new NettyPacketEncoder(),
                // 文件处理
                new FileChannelHandler()
        );
    }
}
